package com.wnxy.admin.controller;


import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.view.PoiBaseView;
import com.wnxy.admin.common.ResponseResult;
import com.wnxy.admin.dto.PageResult;
import com.wnxy.admin.dto.RuleQueryDto;
import com.wnxy.admin.entity.MaintenancePersonnel;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.wnxy.admin.entity.ChargingRules;
import com.wnxy.admin.service.IChargingRulesService;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author All
 * @since 2023-11-29
 */
@RestController
@RequestMapping("/charging-rules")
public class ChargingRulesController {

    private final IChargingRulesService chargingRulesServiceImpl;
    public ChargingRulesController(IChargingRulesService chargingRulesServiceImpl){
        this.chargingRulesServiceImpl = chargingRulesServiceImpl;
    }

    /*
     *  数据导出
     * */
    @GetMapping("/export")
    public void export(ModelMap map,
                       HttpServletRequest request,
                       HttpServletResponse response) {
        List<ChargingRules> chargingRulesList = chargingRulesServiceImpl.list();
        ExportParams params = new ExportParams("计费规则列表", "计费规则列表", ExcelType.XSSF);
        map.put(NormalExcelConstants.DATA_LIST, chargingRulesList);
        map.put(NormalExcelConstants.CLASS, ChargingRules.class);
        map.put(NormalExcelConstants.PARAMS, params);
        map.put(NormalExcelConstants.FILE_NAME, "chargingRulesList");
        PoiBaseView.render(map, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);
    }

    /*
    *  查询计费规则(分页)
    * */
    @GetMapping("/queryRules")
    public ResponseResult queryRules(@ModelAttribute RuleQueryDto ruleQueryDto) {
        PageResult page = chargingRulesServiceImpl.queryRules(ruleQueryDto);
        return ResponseResult.ok(page);
    }

    /*
    *  编辑计费规则
    * */
    @PutMapping("/editRules")
    public ResponseResult editRules(@RequestBody ChargingRules chargingRules) {
        chargingRulesServiceImpl.editRules(chargingRules);
        return ResponseResult.ok();
    }

    /*
    *  新增计费规则
    * */
    @PostMapping("/addRules")
    public ResponseResult addRules(@RequestBody ChargingRules chargingRules) {
        chargingRulesServiceImpl.save(chargingRules);
        return ResponseResult.ok();
    }

    /*
    *  批量/删除计费规则
    * */

    @DeleteMapping("/removeRules")
    public ResponseResult removeRules(@RequestBody List<Long> ruleIds) {
        chargingRulesServiceImpl.removeRules(ruleIds);
        return ResponseResult.ok();
    }
}
